package source

import java.util.Properties

import org.apache.flink.api.common.serialization.SimpleStringSchema
import org.apache.flink.streaming.api.scala._
import org.apache.flink.streaming.connectors.kafka.{FlinkKafkaConsumer011, FlinkKafkaProducer011}

/**
  * @author dinghao 
  * @create 2021-09-09 10:05 
  * @message OK
  */
object FKafkaSource {
  def main(args: Array[String]): Unit = { //zkIP topic filterword
    val properties = new Properties()
    properties.setProperty("bootstrap.servers","192.168.1.190:9092,192.168.1.192:9092,192.168.1.193:9092")
    properties.setProperty("group.id","consumer1")
    properties.setProperty("key.deserializer","org.apache.kafka.common.serialization.StringDeserializer")
    properties.setProperty("value.deserializer","org.apache.kafka.common.serialization.StringDeserializer")
    properties.setProperty("auto.offset.reset", "latest")
    val env = StreamExecutionEnvironment.getExecutionEnvironment
    val kafkaData:DataStream[String] = env.addSource(new FlinkKafkaConsumer011[String](
      "xiaofei",new SimpleStringSchema(),properties))
    kafkaData.print
    kafkaData.addSink(new FlinkKafkaProducer011[String](
      "192.168.1.190:9092,192.168.1.192:9092,192.168.1.193:9092",
      "shengchan",new SimpleStringSchema()))
    env.execute("kafka-kafka")
  }
}
